home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / Textra120 / Scripts / unparagraph.textra < prev    next >
Encoding:
Text File  |  1996-02-02  |  3.3 KB  |  151 lines

  1.      /******************************************************************
  2.      *   TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved.  *
  3.      * Freely distributable ONLY as a component of the TEXTRA package. *
  4.      * This banner may not be removed or altered (improvements to the  *
  5.      *    actual program welcome).  Please document and send to me.    *
  6.      *        !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!!          *
  7.      ******************************************************************/
  8.  
  9. /* Usage:  Unparagraph
  10.  *
  11.  * Paragraph is a specialized formatting script.  It operates on
  12.  * the current SELECT range and, using blank lines as paragraph delimeters
  13.  * (like paragraph.textra), truncates each paragraph into a single line.
  14.  *
  15.  * Thes file is then suitable for formatting with Textra's "margin"
  16.  * mode.  Activating the mode will format each paragraph and the
  17.  * user may take it from there.
  18.  *
  19.  */
  20.  
  21. OPTIONS results
  22.  
  23. rex = 0; result = "NOTSUPPORTED"    /*00002*/
  24. textraversion
  25. parse var result maj min rex
  26. if (result == "NOTSUPPORTED") | (rex < 12) then do
  27.     notify "Textra V1.15 or later required for this script."
  28.     exit
  29. end
  30.  
  31.  
  32. get select position
  33.  
  34. if (result == "NO SELECT") then do  /* is nothing selected? */
  35.  
  36.     ask "Unparagraph from cursor to end of file?"
  37.     if (result ~= "YES") then do
  38.         notify "Try selecting some text and trying again."
  39.         exit
  40.     end
  41.     get cursor position
  42.     parse var result startx' 'starty
  43.     lastline
  44.     selectto startx starty
  45.     get select position
  46.  
  47. end
  48.  
  49. /* yes, there is a selection, get it's boundaries */
  50. parse var result   startx ' ' starty ' ' endx ' ' endy
  51.  
  52.  
  53. currx = startx
  54. curry = starty
  55. nomore = 0
  56. bsto = -1
  57.  
  58. /* temporarily make sure auto indent is off */
  59. prefs autoindent read; autoistate = result
  60. prefs autoindent off
  61.  
  62. /* if nothing on the endline is actually selected, don't include it */
  63. if (endx == 0) then  endy = endy - 1
  64.  
  65. gotoxy 0 curry
  66. get cursor char
  67. do while ((result == " ") | (result == "    ") /*TAB*/)
  68.    del
  69.    get cursor char
  70. end
  71.  
  72. curry = curry+1
  73.  
  74. do while ((curry <= endy) & (nomore == 0))
  75.  
  76.     CheckCancel; if (result == CANCEL) then exit   /*00001*/
  77.  
  78.     lib = IsLineBlank(curry)
  79.     if (lib = NO) then do
  80.     
  81.         /* we need to concat with the one above */
  82.         gotoxy 0 curry
  83.         get cursor char
  84.         do while ((result == " ") | (result == "    ") /*TAB*/)
  85.            del
  86.            get cursor char
  87.         end
  88.         gotoxy 0 curry-1
  89.         column "-1"
  90.         left 1
  91.         get cursor char
  92.         parse var result echar
  93.         right 1
  94.         if (echar ~= ' ') & (echar ~= '    '/*TAB*/) then
  95.             text '" "'
  96.         del
  97.         endy = endy - 1
  98.     end
  99.     
  100.     else do
  101.     
  102.         /* line is blank, find next non blank */
  103.         
  104.         blfound = YES
  105.         do while ((curry <= endy) & (nomore == 0) & (blfound = YES))
  106.             curry = curry + 1
  107.             blfound = IsLineBlank(curry)
  108.         end
  109.         if (blfound = NO) then do
  110.             gotoxy 0 curry
  111.             get cursor char
  112.             do while ((result == " ") | (result == "    ") /*TAB*/)
  113.                del
  114.                get cursor char
  115.             end
  116.             curry = curry + 1
  117.         end
  118.     end
  119.     
  120. end
  121.  
  122. /* restore autoindent */
  123. prefs autoindent autoistate
  124.  
  125.  
  126. exit
  127.  
  128.  
  129.  
  130. IsLineBlank:
  131.     parse arg linen
  132.     ifBlank = "NO"
  133. /*
  134.     get line linen
  135.     parse var result linetext
  136.     cmpres = compare(' ',linetext,' ')
  137.     if cmpres = 0 then
  138.         ifBlank = "YES"
  139. */
  140.  
  141.     gotoxy 0 curry
  142.     get cursor char
  143.     do while ((result == " ") | (result == "    ") /*TAB*/)
  144.        right 1
  145.        get cursor char
  146.     end
  147.     if result = "-1" then
  148.         ifBlank = 1
  149.  
  150. return ifBlank
  151.